class_name UnitFireBird
extends UnitFlyMagic


func shoot_magic():
	if not attack_target: return
	await get_tree().create_timer(0.25).timeout
	
	var offset = Vector2(80, 0) if randf() < 0.5 else Vector2(-80, 0)
	shoot_fire_ring_magic(offset)


func shoot_fire_ring_magic(offset: Vector2):
	if not attack_target: return
	
	var target_unit = attack_target as UnitBase
	var target_position = target_unit.ray_cast_point.global_position + offset
	var magic = (ResourceManager.get_resource("particle_fire_ring") as PackedScene).instantiate() as ParticleFireRing
	
	var config = unit_data.config 
	magic.attack = config.main_attack
	magic.critical_rate = config.main_critical_attack_rate
	magic.critical_bonus = config.main_critical_attack_bonus
	magic.knockback = config.main_attack_knockback
	magic.sender = self
	var dir = Vector2.RIGHT if offset.x < 0 else Vector2.LEFT
	magic.dir = dir
	magic.speed = 50
	magic.life_time = 5.0
	
	if config.main_attack_cam_shake:
		magic.hit_cam_shake_strength = config.main_attack_cam_shake_intensity
		magic.hit_cam_shake_duration = config.main_attack_cam_shake_duration
	
	level.particles_parent.add_child(magic)
	magic.global_position = target_position
	magic.set_is_enemy(true)
	magic.set_collision_2_ground(false)


func play_magic_animation():
	animation_player.play("magic")
